package algotithm.leetcode.dp.test198;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/23-21:34
 * @Title 198. 打家劫舍
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1,2,3,1};
        int rob = solution.rob(nums);
        System.out.println(rob);
    }

    public int rob(int[] nums) {
        int n = nums.length;
        if (n == 0) {
            return 0;
        }
        if (n == 1) {
            return nums[0];
        }
        int first = nums[0];
        int second = Math.max(nums[0],nums[1]);
        for (int i = 2; i < n; i++) {
            int tmp = second;
            second = Math.max(first + nums[i],second);
            first = tmp;
        }
        return second;
    }
}
